//
//  NSDate+Date.m
//  BaiSi
//
//  Created by Sycamore on 16/5/5.
//  Copyright © 2016年 Sycamore. All rights reserved.
//

#import "NSDate+Date.h"

@implementation NSDate (Date)

- (BOOL)isThisYear
{
    //获取当前的日历
    NSCalendar *currentCld = [NSCalendar currentCalendar];
    
    //获得日期差值
    NSDateComponents *detalCmp = [currentCld components:NSCalendarUnitYear fromDate:[NSDate date] toDate:self options:NSCalendarWrapComponents];
    return detalCmp.year == 0;

}

- (BOOL)isToday
{
    //获取当前的日历
    NSCalendar *currentCld = [NSCalendar currentCalendar];

    return [currentCld isDateInToday:self];
}

- (BOOL)isYesterday
{
    //获取当前的日历
    NSCalendar *currentCld = [NSCalendar currentCalendar];
    
    return [currentCld isDateInYesterday:self];

}

- (NSDateComponents *)deltaComponentsFromNow
{
    //获取当前的日历
    NSCalendar *currentCld = [NSCalendar currentCalendar];
    
    //获得日期差值
    NSInteger unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay
    | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *deltaCmp = [currentCld components:unit fromDate:self toDate:[NSDate date] options:NSCalendarWrapComponents];
    
    
    return deltaCmp;

}


@end
